{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c3495fe7",
   "metadata": {},
   "source": [
    "* 2022/10/11/week 08\n",
    "* Python笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c22e3f4",
   "metadata": {},
   "source": [
    "## 本周内容\n",
    "\n",
    "0.代码的注释\n",
    "\n",
    "1.用户输入\n",
    "\n",
    "2.格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f9b32fb",
   "metadata": {},
   "source": [
    "# 0.代码的注释\n",
    "\n",
    "> 1.#，一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录。\n",
    "\n",
    "> 2.\"注释内容\"，一般是注释代码块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4dddc05d",
   "metadata": {},
   "source": [
    "## 1.用户输入\n",
    "\n",
    "> 1.input（）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e604a2c5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5fc4757b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:admin\n",
      "密码:12138\n",
      "admin\n",
      "12138\n",
      "欢迎admin登录！\n"
     ]
    }
   ],
   "source": [
    "# 登录系统 迭代1：增加判断功能\n",
    "user1 = \"admin\"\n",
    "password1 = \"12138\"\n",
    "\n",
    "for i in range(3,0,-1): # i 是一个int\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    print(username)\n",
    "    print(password)\n",
    "\n",
    "    # 情景一：输入信息正确，登陆成功\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登录！\")\n",
    "        break\n",
    "    # 情景二：账号不存在或密码错误\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败，请一小时后再来尝试\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码错误！\")\n",
    "            print(\"您还有\"+str(i-1)+\"次尝试机会\") # str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2161b25",
   "metadata": {},
   "source": [
    "## 2.格式化输出\n",
    "> 1.字符串拼接\n",
    "\n",
    "> 2.占位符\n",
    "\n",
    "> 3.format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8d316d22",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名: Frences\n",
      "年龄: 19\n",
      "工作: student\n",
      "地区: 广州\n",
      "收入: 1500\n",
      "'-----INFO OF Frences-----\n",
      "年龄：19\n",
      "工作：student\n",
      "收入：1500\n",
      "地区：广州\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统\n",
    "name = input(\"姓名: \")\n",
    "age = input(\"年龄: \")\n",
    "job = input(\"工作: \")\n",
    "reg = input(\"地区: \")\n",
    "salary = input(\"收入: \")\n",
    "\n",
    "info = ''''-----INFO OF %s-----\n",
    "年龄：%s\n",
    "工作：%s\n",
    "收入：%s\n",
    "地区：%s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ac07ba4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
